package top.wshape1.rpc.registry;

import lombok.extern.slf4j.Slf4j;
import top.wshape1.rpc.common.extension.ExtensionLoader;
import top.wshape1.rpc.config.JJRpcConfig;

/**
 * @author Wshape1
 * @version 1.0
 * @description
 * @since 2024-02-02
 */

@Slf4j
public class RpcRegistryFactory {

    private static final ExtensionLoader<RpcRegistry> loader = ExtensionLoader.getExtensionLoader(RpcRegistry.class);
    private static RpcRegistry registry;

    public static RpcRegistry getRegistry() {
        if (registry == null) {
            registry = loader.getExtension(JJRpcConfig.CONFIG.getRegistry().getType());
        }
        return registry;
    }

    public static void setRegistry(RpcRegistry registry) {
        RpcRegistryFactory.registry = registry;
    }

}
